package com.yodawnla.fishing.scene;

import org.anddev.andengine.entity.sprite.Sprite;

import com.yodawnla.fishing.system.Fonts;
import com.yodawnla.fishing.system.SE;
import com.yodawnla.fishing.system.Tex;
import com.yodawnla.fishing.system.YS;
import com.yodawnla.lib.YoScene;
import com.yodawnla.lib.util.widget.YoButton;
import com.yodawnla.lib.util.widget.YoText;
import com.yodawnla.lib.util.widget.YoTiledButton;

public class TitleScene extends YoScene
{

	public TitleScene()
	{
	}

	@Override
	public void loadScene()
	{

		Sprite bg = new Sprite(0, 0, 480, 800, getTexture(Tex.TitleBg));
		this.attachChild(bg);

		YoButton btn = new YoButton(this, 160, 400, getTexture(Tex.TitleBtn))
		{
			@Override
			public void init()
			{
				YoText text = new YoText(5, 5, Fonts.White20, "Play Game", 20);
				this.attachChild(text);
			}

			@Override
			public void onClickedEvent()
			{
				toScene(YS.StageScene);
			}
		};
		this.attachChild(btn);

		btn = new YoButton(this, 160, 480, getTexture(Tex.TitleBtn))
		{
			@Override
			public void init()
			{
				YoText text = new YoText(5, 5, Fonts.White20, "Rank", 20);
				this.attachChild(text);
			}

			@Override
			public void onClickedEvent()
			{
				toScene(YS.RankScene);
			}
		};
		this.attachChild(btn);
		btn = new YoButton(this, 160, 560, getTexture(Tex.TitleBtn))
		{
			@Override
			public void init()
			{
				YoText text = new YoText(5, 5, Fonts.White20, "Guide", 20);
				this.attachChild(text);
			}

			@Override
			public void onClickedEvent()
			{
				toScene(YS.HandbookScene);
			}
		};
		this.attachChild(btn);

		YoButton fbBtn = new YoButton(this, 6, 6, getTexture(Tex.FbBtn))
		{
			@Override
			public void onPressedEvent()
			{
				playSound(SE.Click);
				showLink("http://www.facebook.com/pages/YoDawnLa-%E9%81%8A%E6%A8%82%E9%BB%A8/473502306006935?ref=stream");
			}
		};
		this.attachChild(fbBtn);

		YoButton rateBtn = new YoButton(this, 77, 6, getTexture(Tex.RateBtn))
		{
			@Override
			public void onPressedEvent()
			{
				playSound(SE.Click);
				showMarketLink();
			}
		};
		this.attachChild(rateBtn);

		YoTiledButton vibrationBtn = new YoTiledButton(this, 339, 6, getTiledTexture(Tex.Tiled.VibrateBtn))
		{
			boolean vibraOn;

			@Override
			public void init()
			{
				vibraOn = isVibrateEnabled();

				if (vibraOn)
					setCurrentTileIndex(0);
				else
					setCurrentTileIndex(1);
			}

			@Override
			public void onClickedEvent()
			{
				vibraOn = !vibraOn;

				setVibrateEnabled(vibraOn);

				if (vibraOn)
				{
					vibrate(200);
					setCurrentTileIndex(0);
				}
				else
					setCurrentTileIndex(1);

				// mSave.setBool(Save.SAVE.VIBRATE, vibraOn);
				playSound(SE.Click);
			}
		};
		mScene.attachChild(vibrationBtn);

		YoTiledButton audioBtn = new YoTiledButton(this, 410, 6, getTiledTexture(Tex.Tiled.AudioBtn))
		{
			boolean audioOn;

			@Override
			public void init()
			{
				audioOn = isAudioEnabled();

				if (audioOn)
					this.setCurrentTileIndex(0);
				else
					this.setCurrentTileIndex(1);
			}

			@Override
			public void onClickedEvent()
			{
				audioOn = !audioOn;

				setAudioEnabled(audioOn);

				if (audioOn)
					this.setCurrentTileIndex(0);
				else
					this.setCurrentTileIndex(1);
			}
		};
		this.attachChild(audioBtn);
	}

}
